package com.wtw.utils

import redis.clients.jedis.{Jedis, JedisPool, JedisPoolConfig}

/**
  * 王庭伟201731102227
  */
object RedisUtil {
  val config = new JedisPoolConfig()
  //最大连接数
  config.setMaxTotal(10)

  //最大空闲连接数
  config.setMaxIdle(5)

  //设置有效性检查
  config.setTestOnBorrow(true)

  val pool = new JedisPool(config, "192.168.120.201", 6379, 10000)

  def getConnection()= {
    pool.getResource
  }

  def returnConnection(jedis: Jedis): Unit = {
    pool.returnResource(jedis)
  }

  def main(args: Array[String]): Unit = {
    val jedis = getConnection()
    println(jedis.get("spark-kafka"))
  }
}
